package com.tools.timetask;

import com.alibaba.fastjson.JSONObject;
import com.bean.TimeDimensionData;
import com.tools.WXDatahubConfig;

import java.sql.Time;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

public class DataMockHelper {

    public static String mockTime(){
        SimpleDateFormat dateFormat = new SimpleDateFormat(WXDatahubConfig.simpleDateFormat);
        Date currentDate = new Date();
//        System.out.println("Current Date: " + dateFormat.format(currentDate));
        return dateFormat.format(currentDate);
    }


    public static String mockTimeSrc(long times){
        SimpleDateFormat dateFormat = new SimpleDateFormat(WXDatahubConfig.simpleDateFormat);
        return dateFormat.format(times);
    }

    static double basicNum = 1730;
//    static double resultNum = 1729;

    public static double mockWaterDeep(double resultNum){
        Random random = new Random();
        int tempNum = random.nextInt(5);
        if(resultNum <=1700.5){
            tempNum = 0;
        }
        if(resultNum >= 1730.6){
            tempNum = 1;
        }
        if(tempNum==0){
            resultNum = resultNum - 0.02;
        }else if(tempNum==4){
            resultNum = resultNum - 0.01;
        }else if(tempNum == 2){
            resultNum = resultNum + 0.01;
        }else if(tempNum == 3){
            resultNum = resultNum + 0.02;
        }

        DecimalFormat df = new DecimalFormat("#.00");
        String formattedNumber = df.format(resultNum);
        double result = Double.parseDouble(formattedNumber);
        return result;
    }

    public static void main(String[] args) {
        Random random = new Random();
        double deepWater = 1728.39;
        int tempNum = random.nextInt(5);
        if(tempNum==0){
            deepWater = deepWater + 0.01;
        }else if(tempNum==1){
            deepWater = deepWater - 0.01;
        }else if(tempNum == 2){
            deepWater = deepWater - 0.01;
        }else if(tempNum == 3){
            deepWater = deepWater - 0.02;
        }
        String timeValue = String.valueOf(deepWater);
        if(timeValue.length()>7){
            timeValue = timeValue.substring(0,7);
        }else if(timeValue.length() == 6){
            timeValue = timeValue+"0";
        }

        System.out.println("初始值:"+timeValue);
        List<TimeDimensionData> timeDimensionData = generateTimeData(deepWater,0);
        for (int i = 0; i < timeDimensionData.size(); i++) {
            System.out.print(timeDimensionData.get(i).getTimeValue()+",");
        }
    }

    public static List<TimeDimensionData> generateTimeData(double value,long timestamp){
        List<TimeDimensionData> list = new ArrayList<>();
        long currentTime = timestamp;
        double tempTime = value;
        for(int i=0;i<12;i++){
            TimeDimensionData data = new TimeDimensionData();
            data.setId(String.valueOf(i));
            data.setStatisticsTime(mockTimeSrc(currentTime));
            currentTime = currentTime - 300000;
            if(i != 0){
                tempTime = mockWaterDeep(tempTime);
            }
            String timeValue = String.valueOf(tempTime);
            if(timeValue.length()>7){
                timeValue = timeValue.substring(0,7);
            }else if(timeValue.length()<7){
                timeValue = timeValue+"0";
            }
            data.setTimeValue(timeValue);
            data.setZoningCode(WXDatahubConfig.zoningCode);
            data.setParentZoningCode(WXDatahubConfig.pareZoningCode);
            data.setZoningName(WXDatahubConfig.zoningName);
            data.setTimeDim("hour");
            list.add(data);
        }
        return list;
    }
}
